package org.scboy.common.dynamic.node.entityNode;

import java.util.List;

import org.scboy.common.annotation.ScriptNode;
import org.scboy.common.dynamic.node.BaseNode;
import org.scboy.utils.entitys.coobi.Model;

import cn.hutool.json.JSONObject;


@ScriptNode("LIST_REMOVE_ENTITY")
public class ListRemoveNode extends BaseNode{

	Integer dataIndex=null;
	
	@Override
	public void create(JSONObject object) {
		dataIndex=object.getInt("dataIndex");
	}

	@SuppressWarnings("unlikely-arg-type")
	@Override
	public Object run() {
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("----->开始执行："+getNodeName()+" 节点ID："+this.getId());
		}
		
		if(dataIndex==null) {
			throw new RuntimeException(getNodeName()+"必须存在删除的索引值。");
		}
		
		List<Model> listData=getSourceListData("params", true ,Model.class);
		
		/**
		 * 流出节点
		 */
		BaseNode runTo = getRunTo("to");
		
		listData.remove(dataIndex);
		
		this.setData("data", listData);
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("缓存数据：\r\n"+entityToString(this.getDataAll()));
			this.script.appendMsg("执行下个节点："+runTo.getNodeName()+" 节点ID："+runTo.getId());
		}
		return runTo.run();
	}
	
}
